package uniLearn.data;

import java.math.BigDecimal;
import java.util.*;

public class AssignmentCollector {
	//define
	//public static final int ID_MAX_LENGTH = 10;
	public static final int NAME_MAX_LENGTH = 50;
	
	//variable
	private int id;
	private String name;
	private String unitID;
	private Date deadline;
	private BigDecimal fullMark;
	private String info;
	private int groupSize;
	
	private boolean isSubmission;
	private boolean isMarking;
	
	//constructor
	public AssignmentCollector(int id, String name, String unitID, Date deadline, int groupSize) {
		//set name with checking
		this.setName(name);
		
		if(unitID.isEmpty() || unitID.length() > Units.ID_MAX_LENGTH) {
			//error
		}
		
		this.id = id;
		this.unitID = unitID;
		this.deadline = deadline;
		this.groupSize = groupSize;
		this.fullMark = BigDecimal.ZERO;
		this.isMarking = false;
		this.isSubmission = false;
	}

	//get method
	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getUnitID() {
		return unitID;
	}

	public Date getDeadline() {
		return deadline;
	}

	public String getInfo() {
		return info;
	}
	
	public int getGroupSize() {
		return groupSize;
	}

	public BigDecimal getFullMark() {
		return fullMark;
	}

	public boolean isSubmission() {
		return isSubmission;
	}

	public boolean isMarking() {
		return isMarking;
	}

	//set method
	public void setName(String name) {
		if(name.isEmpty() || name.length() > NAME_MAX_LENGTH)
			this.name = "";
		else
			this.name = name;
	}

	public void setDeadline(Date deadline) {
		this.deadline = deadline;
	}

	public void setInfo(String info) {
		this.info = info;
	}
	
	public void setGroupSize(int groupSize) {
		this.groupSize = groupSize < 0 ? 1 : groupSize;
	}

	public void setFullMark(BigDecimal fullMark) {
		this.fullMark = (fullMark == null || fullMark.signum() < 0) ? BigDecimal.ZERO : fullMark;
	}

	public void setSubmission(boolean isSubmission) {
		this.isSubmission = isSubmission;
	}

	public void setMarking(boolean isMarking) {
		this.isMarking = isMarking;
	}

	//OVervide
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((deadline == null) ? 0 : deadline.hashCode());
		result = prime * result
				+ ((fullMark == null) ? 0 : fullMark.hashCode());
		result = prime * result + groupSize;
		result = prime * result + id;
		result = prime * result + ((info == null) ? 0 : info.hashCode());
		result = prime * result + (isMarking ? 1231 : 1237);
		result = prime * result + (isSubmission ? 1231 : 1237);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((unitID == null) ? 0 : unitID.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AssignmentCollector other = (AssignmentCollector) obj;
		if (deadline == null) {
			if (other.deadline != null)
				return false;
		} else if (!deadline.equals(other.deadline))
			return false;
		if (fullMark == null) {
			if (other.fullMark != null)
				return false;
		} else if (!fullMark.equals(other.fullMark))
			return false;
		if (groupSize != other.groupSize)
			return false;
		if (id != other.id)
			return false;
		if (info == null) {
			if (other.info != null)
				return false;
		} else if (!info.equals(other.info))
			return false;
		if (isMarking != other.isMarking)
			return false;
		if (isSubmission != other.isSubmission)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (unitID == null) {
			if (other.unitID != null)
				return false;
		} else if (!unitID.equals(other.unitID))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("AssignmentCollector [id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append(", unitID=");
		builder.append(unitID);
		builder.append(", deadline=");
		builder.append(deadline);
		builder.append(", fullMark=");
		builder.append(fullMark);
		builder.append(", info=");
		builder.append(info);
		builder.append(", groupSize=");
		builder.append(groupSize);
		builder.append(", isSubmission=");
		builder.append(isSubmission);
		builder.append(", isMarking=");
		builder.append(isMarking);
		builder.append("]");
		return builder.toString();
	}

}
